﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OxyPlotDemo
{
    class RecommendationSystem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private string recommendation;
        public string Recommendation
        {
            get { return recommendation; }
            set
            {
                recommendation = value;
                if (PropertyChanged != null)
                {
                    PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Recommendation"));
                }
            }
        }
        private string[] subRecommendation = new string[9];
        public void GiveRecommendation(List<SensorData> sensorDatas)
        {
            Recommendation = null;
            bool doLessSports = false;

            if (sensorDatas[0].SensorValue < -7 || sensorDatas[0].SensorValue > 35)
            {
                subRecommendation[0] = "停止户外锻炼";
            }
            else if (sensorDatas[0].SensorValue < 10 && sensorDatas[0].SensorValue > 3)
            {
                subRecommendation[0] = "马拉松";
            }
            else if (sensorDatas[0].SensorValue < 23 && sensorDatas[0].SensorValue > 17)
            {
                subRecommendation[0] = "大部分运动均可进行";
            }
            else if (sensorDatas[0].SensorValue < 33 && sensorDatas[0].SensorValue > 31)
            {
                subRecommendation[0] = "室外游泳";
            }
            else
            {
                subRecommendation[0] = null;
            }

            if (sensorDatas[1].SensorValue >= 60)
            {
                subRecommendation[1] = "停止户外锻炼";
            }
            else if (sensorDatas[1].SensorValue >= 50)
            {
                subRecommendation[1] = "跑步";
            }
            else
            {
                subRecommendation[1] = null;
            }

            if (sensorDatas[2].SensorValue > 150)
            {
                subRecommendation[2] = "停止户外锻炼";
            }
            else if (sensorDatas[2].SensorValue > 115)
            {
                doLessSports = true;
                subRecommendation[2] = null;
            }
            else
            {
                subRecommendation[2] = null;
            }

            if (sensorDatas[3].SensorValue <= 6)
            {
                subRecommendation[3] = null;
            }
            else if (sensorDatas[3].SensorValue <= 9)
            {
                subRecommendation[3] = "使用防晒品";
                doLessSports = true;
            }
            else
            {
                subRecommendation[3] = "停止户外锻炼";
            }

            if (sensorDatas[4].SensorValue <= 60)
            {
                subRecommendation[4] = null;
            }
            else if (sensorDatas[4].SensorValue <= 80)
            {
                subRecommendation[4] = null;
                doLessSports = true;
            }
            else
            {
                subRecommendation[4] = "停止户外锻炼";
            }

            if (sensorDatas[5].SensorValue <= 960)
            {
                subRecommendation[5] = "停止户外锻炼";
            }
            else
            {
                subRecommendation[5] = null;
            }

            if (sensorDatas[6].SensorValue > 160)
            {
                subRecommendation[6] = "警告！体征异常！";
            }
            else
            {
                subRecommendation[6] = null;
            }

            if (sensorDatas[7].SensorValue > 37.4 || sensorDatas[7].SensorValue < 36)
            {
                subRecommendation[7] = "警告！体征异常！";
            }
            else
            {
                subRecommendation[7] = null;
            }

            for (int i = 0; i < 9; i++)
            {
                if (subRecommendation[i] == null)
                {
                    continue;
                }
                else if (subRecommendation[i] == "停止户外锻炼")
                {
                    Recommendation = "停止户外锻炼";
                    break;
                }
                else if (subRecommendation[i] != null)
                    Recommendation += "," + subRecommendation[i];
            }
            for (int i = 0; i < 9; i++)
            {
                if (subRecommendation[i] == "警告！体征异常！")
                {
                    Recommendation = "警告！体征异常！";
                    break;
                }
            }
            if (doLessSports && Recommendation != "停止户外锻炼" && Recommendation != "警告！体征异常！")
            {
                Recommendation += "," + "减少运动";
            }
            while (Recommendation != null)
            {
                if (Recommendation.Substring(0, 1) == ",")
                    Recommendation = Recommendation.Remove(0, 1);
                else
                    break;
            }
            if (Recommendation == null)
            {
                Recommendation = "无";
            }
        }
    }
}
